<?php

require_once '../include/common.inc.php';

if (!checkAdmin()) {
    header("LOCATION:index.php");
    exit;
}

$menu_index = 2;
$page_title = 'TABLA';
$guide_message = 'Customer | Order';


$page_url = 'c_order_list.php?';
$ppp = 20;

$sql = "SELECT `id` FROM `order`";
$query = $db->query($sql);
$sql_all_num = $db->num_rows($query);

// *** page code start ***
getMyParam('page');
$page = empty($page) || !ispage($page) ? 1 : $page;
$start_limit = ($page - 1) * $ppp;
if($start_limit > $sql_all_num) {
    $start_limit = 0;
    $page = 1;
}
// *** page code end ***


$sql = "SELECT `id`, `product_info`, `totalcount`, `totalcost`, `user_id`, `date` FROM `order` ORDER BY `date` DESC LIMIT $start_limit, $ppp";
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
    $out_ary[] = $rs;
    $user_id_ary[] = $rs['user_id'];
}

$user_info_ary = array();
if (!empty($user_id_ary)) {
	$user_id_str = implode(",", $user_id_ary);
	$sql = "SELECT `id`, `username`, `firstname`, `lastname`, `type` FROM `user` WHERE `id` IN (" . $user_id_str . ")";
	$query = $db->query($sql);
	while($rs = $db->fetch_array($query)) {
	    $user_info_ary[$rs['id']] = $rs;
	}
}

$page_show = getPageStr($sql_all_num, $page, $ppp, $page_url);

include_once(TABLA_ROOT . 'admin/menu_list.php');
require_once PrintEot('a_header');
require_once PrintEot('a_c_order_list');
require_once PrintEot('a_footer');

?>